﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommHelper
{
    public class Log
    {
        private static object lockobj = new object();

        public static void Write(String text)
        {
            lock (lockobj)
            {
                String Folder = System.AppDomain.CurrentDomain.BaseDirectory + "\\Logs";
                if (!System.IO.Directory.Exists(Folder))
                {
                    System.IO.Directory.CreateDirectory(Folder);
                }
                String File = Folder + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
                System.IO.StreamWriter sw = new System.IO.StreamWriter(File, true);
                sw.WriteLine(DateTime.Now + ":" + text);
                sw.Flush();
                sw.Close();
                Console.WriteLine(text);
            }
        }

        public static void Write(String Folder, String text)
        {
            lock (lockobj)
            {
                String LogFolder = System.AppDomain.CurrentDomain.BaseDirectory + "\\Logs\\" + Folder;
                if (!System.IO.Directory.Exists(LogFolder))
                {
                    System.IO.Directory.CreateDirectory(LogFolder);
                }
                String File = LogFolder + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
                System.IO.StreamWriter sw = new System.IO.StreamWriter(File, true);
                sw.WriteLine(DateTime.Now + ":" + text);
                sw.Flush();
                sw.Close();
                Console.WriteLine(text);
            }
        }

    }
}
